package com.ecoolex.hotel.saas.core.manager;

import com.ecoolex.hotel.saas.core.dao.PresaleCouponOrderAfterSalesRecordDAO;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderAfterSalesRecord;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderAfterSalesRecordExample;
import com.ecoolex.hotel.saas.entity.PresaleCouponOrderAfterSalesRecordExample.Criteria;
import com.ecoolex.hotel.saas.enums.PresaleCouponOrderAfterSalesRecordType;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PresaleCouponOrderAfterSalesRecordManager {
	
    @Autowired
    private PresaleCouponOrderAfterSalesRecordDAO dao;
    
    public List<PresaleCouponOrderAfterSalesRecord> afterSalesRecord(Integer afterSalesId) {
    	PresaleCouponOrderAfterSalesRecordExample example = new PresaleCouponOrderAfterSalesRecordExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andAfterSalesIdEqualTo(afterSalesId);
		return dao.selectByExample(example);
	}
    
    public void create(Integer afterSalesId, Integer orderId, PresaleCouponOrderAfterSalesRecordType type,
    	String remark,String evidenceImage,String createUser) {
    	PresaleCouponOrderAfterSalesRecord record = new PresaleCouponOrderAfterSalesRecord();
    	record.setAfterSalesId(afterSalesId);
    	record.setOrderId(orderId);
    	record.setContentType(type.real());
    	record.setRemark(remark);
    	record.setEvidenceImage(evidenceImage);
    	record.setDeleted(PresaleCouponOrderAfterSalesRecord.NOT_DELETED);
    	record.setCreateUser(createUser);
    	record.setCreateTime(Date.from(Instant.now()));
    	record.setUpdateUser(createUser);
    	record.setUpdateTime(Date.from(Instant.now()));
    	dao.insert(record);
    }
}